package com.coin.controller;

import com.coin.domain.SysMenu;
import com.coin.model.*;
import com.coin.service.SysRolePrivilegeService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: 李 力
 * @Date: 2025/5/27
 * @Description: com.coin.controller
 * @version: 1.0
 */
@Api(value = "角色权限配置")
@RestController
@RequestMapping
public class SysRolePrivilegeController {

    @Autowired
    private SysRolePrivilegeService rolePrivilegeService;

    /**
     * @Description: 查询各菜单下对应角色的权限
     * @Author: 李 力
     * @Date: 2025/5/27
     * @Param: roleId
     * @return: R
     */
    @GetMapping("/roles_privileges")
    @ApiOperation(value = "查询角色的权限列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色的ID")
    })
    public R<List<SysMenu>> getMenusByRoleId(@RequestParam Long roleId) {
        List<SysMenu> sysMenus = rolePrivilegeService.getMenusByRoleId(roleId);
        return R.ok(sysMenus);
    }

    /**
     * @Description: 授予角色某种权限
     * @Author: 李 力
     * @Date: 2025/5/27
     * @Param: rolePrivilegesParam
     * @return: R
     */
    @PostMapping("/grant_privileges")
    @ApiOperation(value = "授予角色某种权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rolePrivilegesParam", value = "rolePrivilegesParam json数")
    })
    public R grantPrivileges(@RequestBody RolePrivilegesParam rolePrivilegesParam) {
        boolean result = rolePrivilegeService.grantPrivileges(rolePrivilegesParam);
        return result ? R.ok("成功") : R.fail("失败");
    }
}
